package hhm.javamode.singleton;

public class Test1 {
	/**
	 * 懒汉式单例模式 MySingleton
	 */
	public static void lazy() {
		System.out.println("-----------------懒汉式单例模式----------------");
		System.out.println("第一次取得实例（懒汉式）");
		LazySingleton s1 = LazySingleton.getInstance();
		System.out.println("第二次取得实例（懒汉式）");
		LazySingleton s2 = LazySingleton.getInstance();
		if (s1 == s2) {
			System.out.println(">>>>>s1,s2为同一实例（懒汉式）<<<<<");
		}
		System.out.println();
	}

	public static void hunger() {
		System.out.println("-----------------饿汉式单例模式----------------");
		System.out.println("第一次取得实例（饿汉式）");
		HungerSingleton s1 = HungerSingleton.getInstance();
		System.out.println("第二次取得实例（饿汉式）");
		HungerSingleton s2 = HungerSingleton.getInstance();
		if (s1 == s2) {
			System.out.println(">>>>>s1,s2为同一实例（饿汉式）<<<<<");
		}
		System.out.println();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// 懒汉式
		lazy();
		// 饿汉式
		hunger();

	}
}
